﻿namespace Pathfinding
{
    using System;
    using UnityEngine;

    internal class DynamicObstacle : MonoBehaviour
    {
        private Point3D lastPos;
        public Pathfinder pathfinder;

        private void OnDestroy()
        {
            if (this.pathfinder != null)
            {
                this.pathfinder.dynamicObstacles.Remove(this.pos);
            }
        }

        private void Update()
        {
            if ((this.pathfinder != null) && (this.lastPos != this.pos))
            {
                this.pathfinder.dynamicObstacles.Add(this.pos);
                this.pathfinder.dynamicObstacles.Remove(this.lastPos);
                this.lastPos = this.pos;
            }
        }

        private Point3D pos
        {
            get
            {
                return base.transform.position;
            }
        }
    }
}

